import axios from "axios";

//eslint-disable-next-line
export default {
    // 新增商品
    add: ({ name, count, price, childId, isAttend, desc, image }) =>
        axios.post('/api/comms/add', {
            name, count, price, childId, isAttend, desc, image
        })
            .then(({ data }) => data),
    // 获取所有商品
    getAll: ({ curPage, eachPage, childId }) =>
        axios.get('/api/comms/getAll', {
            params: { curPage, eachPage, childId }
        })
            .then(({ data }) => data),
    // 删除商品
    del: ({ _id }) =>
        axios.delete(`/api/comms/del`, {
            params: { _id }
        })
            .then(({ data }) => data),
    // 获取_id对应的商品
    getOne: ({ _id }) =>
        axios.get('/api/comms/getOne', {
            params: { _id }
        })
            .then(({ data }) => data),
    // 更新商品信息
    reset: ({ _id, childId, name, count, price, desc }) =>
        axios.patch('/api/comms/reset', {
            _id, childId, name, count, price, desc
        })
            .then(({ data }) => data),
    // 获取所有商品
    getAllComms: () =>
        axios.get('/api/comms/getComms', {})
            .then(({ data }) => data),
    // 删除图片
    deleteImg: ({ _id, url }) =>
        axios.delete(`/resource/comms/${_id}/image/${encodeURIComponent(url)} `, {
            params: { _id, url }
        })
            .then(({ data }) => data),
    // 删除海报
    deletePoster: ({ _id, url }) =>
        axios.delete(`/resource/comms/${_id}/commsPoster/${encodeURIComponent(url)} `, {
            params: { _id, url }
        })
            .then(({ data }) => data),
}